﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<title>Nugget Sub Protocol Sample</title>
        <script type="text/javascript">
            var ws;
            var start = function () {
                // the "debug" element is used to display information
                var debug = document.getElementById('debug');
                debug.innerHTML += "connecting to server ..<br/>";

                // create a new websocket and connect
                // not that the web socket uses the subprotocol "post"
                ws = new WebSocket('ws://localhost:8181/subsample', 'post');

                ws.onmessage = function (evt) {
                    debug.innerHTML += evt.data + '<br/>';
                };

                ws.onopen = function () {
                    debug.innerHTML += '.. connection open<br/>';
                };

                ws.onclose = function () {
                    debug.innerHTML += '.. connection closed<br/>';
                }

            }

            // when the button is clicked - do this
            var clicks = function () {
                // get the author and the message body
                var name = document.getElementById('name').value;
                var msg = document.getElementById('message').value;
                // create a json string
                var json = JSON.stringify({ author: name, body: msg });
                debug.innerHTML += "sending " + json + "<br/>";
                // send it
                ws.send(json);
            }

            window.onload = start;
        </script>
	</head>
	<body>
        <input type="text" name="name" id="name" placeholder="name"/><br />
        <textarea id="message" cols="50" rows="5" placeholder="message"></textarea><br />
        <input type="button" value="Send" id="submit_button" onclick="clicks()" />
        <pre id="debug"></pre>
	</body>
</html>